package com.ja.openchat.ui.found;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;

import com.google.android.material.tabs.TabLayout;
import com.ja.openchat.BR;
import com.ja.openchat.R;
import com.ja.openchat.ui.base.BaseFragmentPagerAdapter;
import com.ja.openchat.ui.base.JaBaseActivity;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class CircleTopicActivity extends JaBaseActivity implements OnCirclePagerListener{

    @BindView(R.id.tabs)
    TabLayout tabs;
    @BindView(R.id.viewPager)
    ViewPager viewPager;

    public static void start(Context context, String topicInfo){
        Intent intent = new Intent(context,CircleTopicActivity.class);
        intent.putExtra("topic",topicInfo);
        context.startActivity(intent);
    }

    private int currentIndex = 0;
    @Override
    public void initData() {
        String topicName = "";
        if(getIntent()!=null){
            topicName = getIntent().getStringExtra("topic");
        }
        setTitle(String.format("#%s",topicName));
        List<Fragment> mFragments = new ArrayList<>();
        mFragments.add(CircleHomeFragment.newInstance(0, topicName));
        mFragments.add(CircleHomeFragment.newInstance(1, topicName));
        mFragments.add(CircleHomeFragment.newInstance(2, topicName));

        List<String> titlePager = new ArrayList<>();
        titlePager.add(getString(R.string.recommend_text));
        titlePager.add(getString(R.string.newest_text));
        titlePager.add(getString(R.string.hottest_text));

        BaseFragmentPagerAdapter pagerAdapter = new BaseFragmentPagerAdapter(getSupportFragmentManager(), mFragments, titlePager);
        viewPager.setAdapter(pagerAdapter);
        viewPager.setOffscreenPageLimit(titlePager.size());
        tabs.setupWithViewPager(viewPager);
        tabs.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                currentIndex = tab.getPosition();
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @Override
    protected boolean isHaveButterKnife() {
        return true;
    }

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_circle_topic;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public int getCurrentIndex() {
        return currentIndex;
    }
}
